﻿using HCQ2_Common;
using HCQ2_Model.ViewModel;
using HCQ2_Model.VR.Params;
using HCQ2_Model.VRDD.InputDto._0531;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace HCQ2UI_Logic.DocumentController
{
    /// <summary>
    ///  度度圈后台控制器
    /// </summary>
    public class VRCircleController: BaseLogic
    {
        //***************************1.0 度度圈商品关联*******************************
        #region 1.0 默认首次进入度度圈关联 + ActionResult CircleList()
        /// <summary>
        ///  默认首次进入度度圈关联
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult CircleRelList()
        {
            return View();
        }
        #endregion

        #region 1.1 初始化度度圈关联列表 + ActionResult InitCircleTable()
        /// <summary>
        ///  初始化度度圈关联列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult InitCircleTable()
        {
            int page = RequestHelper.GetIntByName("page"),
                rows = RequestHelper.GetIntByName("rows"),
                store_id = RequestHelper.GetIntByName("store_id");//店铺id
            string keyword = RequestHelper.GetDeStrByName("keyword");
            int total;
            var list = operateContext.bllSession.T_VRDDCircleCourseRelevance.GetCircleRelList(store_id, keyword, page, rows, out total);
            TableModel tModel = new TableModel()
            {
                total = total,
                rows = list
            };
            return Json(tModel, JsonRequestBehavior.AllowGet);
        }
        #endregion

        #region 1.2 删除关联 + ActionResult DeleteNode()
        /// <summary>
        ///  1.2 删除关联
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult DeleteNode()
        {
            string id = RequestHelper.GetStrByName("id");//关联课程id集合
            if(string.IsNullOrEmpty(id))
                return operateContext.RedirectAjax(1, "关联课程id信息异常~", "", "");
            int mark = operateContext.bllSession.T_VRDDCircleCourseRelevance.DeleteCircleRel(id);
            if (mark > 0)
                return operateContext.RedirectAjax(0, "关联删除成功~", "", "");
            return operateContext.RedirectAjax(1, "关联删除失败~", "", "");
        }
        #endregion

        //***************************2.0 添加度度圈商品关联*******************************
        #region 2.0 默认首次进入添加度度圈商品关联 + ActionResult CircleList()
        /// <summary>
        ///  默认首次进入添加度度圈商品关联
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult AddCircleRel()
        {
            return View();
        }
        #endregion

        #region 2.1 初始化添加度度圈列表 + ActionResult InitCircleRelTable()
        /// <summary>
        ///  初始化添加度度圈列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult InitCircleRelTable()
        {
            int page = RequestHelper.GetIntByName("page"),
                rows = RequestHelper.GetIntByName("rows"),
                store_id = RequestHelper.GetIntByName("store_id");//店铺id
            string keyword = RequestHelper.GetDeStrByName("keyword");
            int total;
            var list = operateContext.bllSession.T_VRDDCircleCourseRelevance.GetAddCircleRelList(store_id, keyword, page, rows, out total);
            TableModel tModel = new TableModel()
            {
                total = total,
                rows = list
            };
            return Json(tModel, JsonRequestBehavior.AllowGet);
        }
        #endregion

        #region 2.2 添加店铺课程关联 + ActionResult AddNode(DocTreeModel model)
        /// <summary>
        ///   添加店铺课程关联
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult AddStoreCourseRel()
        {
            int store_id = RequestHelper.GetIntByName("store_id");//店铺id
            string course_id = RequestHelper.GetStrByName("course_id");//关联课程id集合
            if (store_id <= 0)
                return operateContext.RedirectAjax(1, "店铺id信息异常~", "", "");
            if (string.IsNullOrEmpty(course_id))
                return operateContext.RedirectAjax(1, "关联课程id信息异常~", "", "");
            string[] ids = course_id.Split(',');
            foreach (string id in ids)
            {
                operateContext.bllSession.T_VRDDCircleCourseRelevance.Add(new HCQ2_Model.T_VRDDCircleCourseRelevance
                {
                    store_id = store_id,
                    course_id = Helper.ToInt(id),
                    create_id = HCQ2UI_Helper.OperateContext.Current.Usr.user_id,
                    create_date = DateTime.Now
                });
            }
            return operateContext.RedirectAjax(0, "添加店铺关联课程成功~", "", "");
        }
        #endregion

        //***************************3.0 订单管理-点播列表*******************************
        #region 3.0 默认首次进入点播列表 + ActionResult PlayList()
        /// <summary>
        ///  默认首次进入点播列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult PlayList()
        {
            return View();
        }
        #endregion

        #region 3.1 初始化播放列表 + ActionResult InitPlayTable()
        /// <summary>
        ///  初始化播放列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult InitPlayTable()
        {
            int page = RequestHelper.GetIntByName("page"),
                rows = RequestHelper.GetIntByName("rows"),
                playStatus = RequestHelper.GetIntByName("playStatus");//状态
            string userName = RequestHelper.GetDeStrByName("userName");//关键字
            int total;
            var list = operateContext.bllSession.T_VRPlayList.GetPlayList(page, rows, playStatus, userName, out total);
            TableModel tModel = new TableModel()
            {
                total = total,
                rows = list
            };
            return Json(tModel, JsonRequestBehavior.AllowGet);
        }
        #endregion
    }
}